package de.programmerspain.rv3sf.api;

import org.apache.commons.lang3.Validate;

/**
 * A simple class used to configure a <code>GammaTable</code> instance.
 * 
 * @author Markus Lang (m@rkus-lang.de) | http://programmers-pain.de/ | https://code.google.com/p/rainbowduino-v3-streaming-firmware/
 */
public class GammaTableConfiguration {
	private short minRed;
	private short maxRed;
	private short minGreen;
	private short maxGreen;
	private short minBlue;
	private short maxBlue;
	
	/**
	 * @param minRed the min value for the red color
	 * @param maxRed the max value for the red color
	 * @param minGreen the min value for the green color
	 * @param maxGreen the max value for the green color
	 * @param minBlue the min value for the blue color
	 * @param maxBlue the max value for the blue color
	 */
	public GammaTableConfiguration(short minRed, short maxRed, short minGreen, short maxGreen, short minBlue, short maxBlue) {
		this.validateRange(minRed);
		this.validateRange(maxRed);
		this.validateRange(minGreen);
		this.validateRange(maxGreen);
		this.validateRange(minBlue);
		this.validateRange(maxBlue);
		this.validate(minRed, maxRed);
		this.validate(minGreen, maxGreen);
		this.validate(minBlue, maxBlue);
		this.minRed = minRed;
		this.maxRed = maxRed;
		this.minGreen = minGreen;
		this.maxGreen = maxGreen;
		this.minBlue = minBlue;
		this.maxBlue = maxBlue;
	}
	
	/**
	 * @return the min value for the red color
	 */
	public short getMinRed() {
		return this.minRed;
	}

	/**
	 * @return the max value for the red color
	 */
	public short getMaxRed() {
		return this.maxRed;
	}

	/**
	 * @return the min value for the green color
	 */
	public short getMinGreen() {
		return this.minGreen;
	}

	/**
	 * @return the max value for the green color
	 */
	public short getMaxGreen() {
		return this.maxGreen;
	}

	/**
	 * @return the min value for the blue color
	 */
	public short getMinBlue() {
		return this.minBlue;
	}

	/**
	 * @return the max value for the blue color
	 */
	public short getMaxBlue() {
		return this.maxBlue;
	}
	
	/**
	 * returns the min value for the given <code>colorEnum</code> color
	 * 
	 * @param color the colorEnum instance
	 * @return the min value
	 */
	public short getMin(ColorEnum color) {
		switch (color) {
		case RED:
			return this.minRed;
		case GREEN:
			return this.minGreen;
		case BLUE:
			return this.minBlue;
		default:
			throw new IllegalArgumentException("unknown color: " + color);
		}
	}
	
	/**
	 * returns the max value for the given <code>colorEnum</code> color
	 * 
	 * @param color the colorEnum instance
	 * @return the max value
	 */
	public short getMax(ColorEnum color) {
		switch (color) {
		case RED:
			return this.maxRed;
		case GREEN:
			return this.maxGreen;
		case BLUE:
			return this.maxBlue;
		default:
			throw new IllegalArgumentException("unknown color: " + color);
		}
	}
	
	// helper method to validate the range of the given color value
	private void validateRange(short value) {
		Validate.validState(value >= 0);
		Validate.validState(value <= 255);
	}

	// helper method to validate the min and max values against each other
	private void validate(short minValue, short maxValue) {
		Validate.validState(maxValue > minValue);
	}
}
